package com.tianbing.adlottery.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.fengniu.ejb.business.ITagLogBusiness;
import com.fengniu.ejb.dao.ICategoryDao;
import com.fengniu.ejb.dao.IContentDao;
import com.fengniu.ejb.dao.ISiteDao;
import com.fengniu.ejb.dao.ISystemDao;
import com.fengniu.ejb.dao.IUserDao;
import com.fengniu.ejb.entity.Content2Content;
import com.fengniu.ejb.entity.Site;
import com.tianbing.adlottery.global.IConstants;
import com.tianbing.adlottery.helper.SkinUtils;

/**
 * MultiActionController for the image list/upload UI.
 * 
 * @author Conan Chen
 * @since 2006.12.15
 */
public class TagLogController extends MultiActionController {
	Logger logger = Logger.getLogger(TagLogController.class.getName());


	private String listTagLogLinkView;


	private ISiteDao siteDao;

	private IUserDao userDao;

	private IContentDao contentDao;

	private ICategoryDao categoryDao;

	private ITagLogBusiness tagLogBusiness;

	private SkinUtils skinUtils;

	private ISystemDao systemDao;

	public ModelAndView listTagLogLink(HttpServletRequest request, HttpServletResponse response) throws Exception {

		ModelAndView mv = new ModelAndView(listTagLogLinkView);
		Map model = mv.getModel();
		String srcUrl = ServletRequestUtils.getStringParameter(request, "src", null);
		model.put("srcUrl", srcUrl);
		logger.info("srcUrl=" + srcUrl);

		Integer pgno = ServletRequestUtils.getIntParameter(request, "pgno", 0);
		Integer pgsize = ServletRequestUtils.getIntParameter(request, "pgsize", 30);

		List<Content2Content> relatedUrls = tagLogBusiness.getListRelatedUrls(srcUrl, pgno, pgsize);
		model.put("relatedUrls", relatedUrls);

		//---------for testing purpose,export taglogs
		tagLogBusiness.exportTagLogs(0, 10);
		//---------/for testing purpose,export taglogs
		return mv;
	}

	/**
	 * @param listTagLogLinkView the listTagLogLinkView to set
	 */
	public void setListTagLogLinkView(String listTagLogLinkView) {
		this.listTagLogLinkView = listTagLogLinkView;
	}

	/**
	 * @param siteDao the siteDao to set
	 */
	public void setSiteDao(ISiteDao siteDao) {
		this.siteDao = siteDao;
	}

	/**
	 * @param userDao the userDao to set
	 */
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @param contentDao the contentDao to set
	 */
	public void setContentDao(IContentDao contentDao) {
		this.contentDao = contentDao;
	}

	/**
	 * @param categoryDao the categoryDao to set
	 */
	public void setCategoryDao(ICategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	/**
	 * @param tagLogBusiness the tagLogBusiness to set
	 */
	public void setTagLogBusiness(ITagLogBusiness tagLogBusiness) {
		this.tagLogBusiness = tagLogBusiness;
	}

	/**
	 * @param skinUtils the skinUtils to set
	 */
	public void setSkinUtils(SkinUtils skinUtils) {
		this.skinUtils = skinUtils;
	}

	/**
	 * @param systemDao the systemDao to set
	 */
	public void setSystemDao(ISystemDao systemDao) {
		this.systemDao = systemDao;
	}

}
